<template>
  <div>
    <h1>首页</h1>
    <div>
      <button @click="setData">触发全局 setData</button>
      <br>
      <button @click="userSetData">触发 user setData</button>
      <br>
      {{token}} {{appName}}
    </div>
  </div>
</template>

<script>
import {mapMutations, mapGetters} from 'vuex'
// 可以从 vuex 导出一个生成辅助函数的工厂方法
import { createNamespacedHelpers } from 'vuex'
const {mapMutations: userMapMutations} = createNamespacedHelpers('user')

export default {
  computed: {
    ...mapGetters(['token', 'appName'])
  },
  methods: {
    // 全局 setData 映射成 globalSetData
    ...mapMutations(['setData']),
    // ...mapMutations('user', ['setData'])
    // ...mapMutations(['setData'])
    ...userMapMutations({
      userSetData: 'setData'
    })
  }
}
</script>

<style>

</style>